﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ImportKaryawanForm.aspx.cs"
    Inherits="Training.Web.Forms.Administration.Catalog.ImportCabangForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>City Form</title>
    <script src="<%= ResolveUrl("~/scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.validate.wrapper.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.inputmask.bundle.min.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/plupload/moxie.min.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/plupload/plupload.full.min.js") %>" type="text/javascript"></script>
    <link href="<%= ResolveUrl("~/styles/chosen/chosen.min.css") %>" rel="stylesheet"
        type="text/css" />
    <script src="<%= ResolveUrl("~/scripts/chosen/chosen.jquery.min.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.msgBox.v1.js") %>" type="text/javascript"></script>
    <script type="text/javascript">

        $("#btnSave").button({ icons: { primary: "ui-icon-disk"} });
        $("#btnClose").button({ icons: { primary: "ui-icon-close"} });

        $('#btnClose').click(function () {
            parent.$('#dialog').dialog("close");
        });
 
    </script>
    <script type="text/javascript">


        var dom = {

            uploads: $("ul.uploads")
        };

        function showImagePreview(file) {

            var item = $("<li></li>").prependTo(dom.uploads);
            var image = $(new Image()).appendTo(item);

            var preloader = new mOxie.Image();
            preloader.onload = function () {
                preloader.downsize(300, 200);
                image.prop("src", preloader.getAsDataURL());

            };


            preloader.load(file.getSource());

        }

        $(document).ready(function () {

            var uploader = new plupload.Uploader({
                runtimes: 'html5,flash,silverlight',
                browse_button: 'pickfiles',
                container: 'container',
                max_file_size: '5mb',
                url: '<%= ResolveUrl("~/ajaxhandler/administration/catalog/Positionhandler.ashx") %>' + '?method=insert',
                flash_swf_url: '<%= ResolveUrl("~/scripts/plupload/Moxie.swf") %>',
                silverlight_xap_url: '<%= ResolveUrl("~/scripts/plupload/Moxie.xap") %>',
                filters: [
                // { title: "Pdf files", extensions: "pdf" },
                 {title: "Excel files", extensions: "xls,xlsx" }
                //{ title: "Text files", extensions: "txt" },
                //{title: "Image files", extensions: "jpeg,jpg,gif,png" }
                // { title: "Word files", extensions: "doc,docx" },
                //	{ title: "PowerPoint files", extensions: "ppt,pptx" }
		],
                resize: { width: 320, height: 240, quality: 90 }
            });

            uploader.bind('Init', function (up, params) {

                var msg = 'Untuk dapat melakukan proses unggah / upload dokumen, browser anda harus mendukung salah satu teknologi, HTML 5 / Flash / Silverlight';

                if (params.runtime == 'html5') {
                    msg = '';
                } else if (params.runtime == 'flash') {
                    msg = '';
                } else if (params.runtime == 'silverlight') {
                    msg = ''
                }

                if (msg != '') {
                    alert(msg);
                }

            });

            uploader.init();

            uploader.bind('FilesAdded', function (up, files) {

                if (up.files.length > 1) {
                    alert('Hanya diperbolehkan satu file untuk di upload!');
                    return false;
                }

                $.each(files, function (i, file) {
                    $('#filelist').append(
                        '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b>' + '</div>');
                    $('#trImage').hide();
                    showImagePreview(file);
                });



                up.refresh(); // Reposition Flash/Silverlight
            });

            uploader.bind('FileUploaded', function (up, file, info) {

                var err = JSON.parse(info.response);
                alert(err.Message);

            });

            uploader.bind('Error', function (up, err) {

                var errMsg = '';

                switch (err.code) {
                    case (-600):
                        errMsg = 'File tidak boleh lebih dari 5 Mb';
                        break;
                    case (-601):
                        errMsg = 'File harus berformat excel / word/ text / pdf / gambar';
                        break;
                    default:
                        errMsg = err.code + ' - ' + err.message;
                        break;
                }

                alert(errMsg);

                up.refresh(); // Reposition Flash/Silverlight

            });


            // 3. Set the click event to do the validation
            $("#btnSave").click(function () {

                var handlerUrl = '<%= ResolveUrl("~/ajaxhandler/administration/catalog/UploadDataHandler.ashx") %>';

                if (uploader.files.length > 0) // Insert with uploaded file.
                {
                    uploader.settings.url = handlerUrl + '?method=uploadkaryawan';
                    uploader.start();
                }
                else {

                    $.post('<%= ResolveUrl("~/ajaxhandler/administration/catalog/UploadDataHandler.ashx") %>' + '?method=uploadkaryawan',
                                $("#form1")
                                .find("input,textarea,select,hidden")
                                .not("#__VIEWSTATE,#__EVENTVALIDATION")
                                .serialize())
                            .done(function (data) {
                                var r = JSON.parse(data);
                                alert(r.Message);
                            })
                            .fail(function () {
                                alert('Data gagal di simpan!');
                            });

                }

                parent.$('#dialog').dialog('close');
                setTimeout("parent.$('#table').trigger('reloadGrid');", 3000);
                return false;
            });

        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <table border="0">
        <tr>
            <td valign="top">
                File
            </td>
            <td valign="top">
                :
            </td>
            <td>
                <div id="container">
                    <a id="pickfiles" class="plupload_button plupload_add ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary"
                        href="#"><span class="ui-button-icon-primary ui-icon ui-icon-circle-plus" /><span
                            class="ui-button-text">Add Files</span> </a>
                    <br />
                    <div id="filelist">
                    </div>
                    <ul class="uploads">
                        <!-- Will be populated dynamically with LI/IMG tags. -->
                    </ul>
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                &nbsp;
            </td>
            <td>
                <%-- <br />
                <br />
                <br />
                <br />
                <br />
                <br />
                <br />
                <br />--%>
                <div style="text-align: right; padding-top: 10px;">
                    <button id="btnSave" type="button">
                        Save</button>
                    <button id="btnClose" type="button">
                        Close</button>
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                &nbsp;
            </td>
            <td>
                <asp:HiddenField ID="hfID" runat="server" />
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
